package com.zzyl.nursing.service.impl;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.zzyl.common.utils.SecurityUtils;
import com.zzyl.nursing.dto.AlertDataPageQueryDto;
import com.zzyl.nursing.dto.HandleAlertDataDto;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.zzyl.nursing.mapper.AlertDataMapper;
import com.zzyl.nursing.domain.AlertData;
import com.zzyl.nursing.service.IAlertDataService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 报警数据Service业务层处理
 *
 * @author Zhy
 * @date 2025-03-11
 */
@Service
@RequiredArgsConstructor
public class AlertDataServiceImpl extends ServiceImpl<AlertDataMapper, AlertData> implements IAlertDataService {


    //2.1.1 分页查询报警数据
    @Override
    public List<AlertData> pageQueryAlertData(AlertDataPageQueryDto dto) {
        LambdaQueryWrapper<AlertData> query = new LambdaQueryWrapper<>();
        query.eq(dto.getDeviceName()!=null && !dto.getDeviceName().isEmpty(),AlertData::getDeviceName,dto.getDeviceName())
                .eq(dto.getStatus()!=null,AlertData::getStatus,dto.getStatus())
                .between(dto.getStartTime()!=null  && dto.getEndTime()!=null,AlertData::getCreateTime,dto.getStartTime(),dto.getEndTime());

        return this.list(query);
    }

    //2.1.2 处理设备报警数据
    @Override
    public void handleAlertData(HandleAlertDataDto handleAlertDataDto) {
        LambdaQueryWrapper<AlertData> query = new LambdaQueryWrapper<>();
        query.eq(AlertData::getId,handleAlertDataDto.getId());
        AlertData alertData = this.getOne(query);
        alertData.setStatus(1);
        alertData.setProcessingResult(handleAlertDataDto.getProcessingResult());
        alertData.setProcessingTime(handleAlertDataDto.getProcessingTime());
        this.update(alertData,query);
    }
}
